package com.itheima.ydd.controller;


import com.itheima.ydd.common.ResultData;
import com.itheima.ydd.entity.SysMenu;
import com.itheima.ydd.service.ISysMenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * <p>
 * 菜单表 前端控制器
 * </p>
 *
 * @author author
 * @since 2022-05-22
 */
@RestController
@RequestMapping("/sys_menu")
@Slf4j
public class SysMenuController {

    @Autowired
    private ISysMenuService sysMenuService;

    @GetMapping("/allData")
    public ResultData allData(){
        log.info("allDatao---------------------------------------");
        return sysMenuService.allData();
    }


    @GetMapping("/rowInfo")
    public ResultData rowInfo(Integer id){
        SysMenu sysMenu = sysMenuService.getById(id);
        return ResultData.ok("",sysMenu);
    }

    @PostMapping("/update")
    public ResultData update(@RequestBody SysMenu sysMenu){
        sysMenuService.updateById(sysMenu);
        return ResultData.ok("","");
    }

    @GetMapping("/del")
    public ResultData delete(Integer id){
        sysMenuService.removeById(id);
        return ResultData.ok("","");
    }

    @PostMapping("/add")
    public ResultData add(@RequestBody SysMenu sysMenu){
        sysMenu.setCreateDate(LocalDateTime.now());
        log.info(sysMenu.toString());
        sysMenuService.save(sysMenu);
        return ResultData.ok("","");

    }
}
